﻿//Write a program that exchanges bits 3, 4 and 5 with bits 
//24, 25 and 26 of given 32-bit unsigned integer.

using System;

namespace ExchangeBits
{
    class ExchangeBits
    {
        static void Main()
        {
            Console.Write("Please enter the number n = ");
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine("Your number in binary is: " + Convert.ToString(n, 2));

            int bit3 = (n >> 3) & 1;
            int bit24 = (n >> 24) & 1;
            n = n & (~(1 << 24)) | (bit3 << 24);
            n = n & (~(1 << 3)) | (bit24 << 3);

            int bit4 = (n >> 4) & 1;
            int bit25 = (n >> 25) & 1;
            n = n & (~(1 << 25)) | (bit4 << 25);
            n = n & (~(1 << 4)) | (bit25 << 4);

            int bit5 = (n >> 5) & 1;
            int bit26 = (n >> 26) & 1;
            n = n & (~(1 << 26)) | (bit5 << 26);
            n = n & (~(1 << 5)) | (bit26 << 5);
            Console.WriteLine("The new number is: {0}", n);
            Console.WriteLine("The new number in binary is: " + Convert.ToString(n, 2));
        }
    }
}
